package com.gm.sfc.logic;

import java.util.HashMap;
import java.util.LinkedList;

import com.gm.sfc.db.DatabaseHelper;
import com.gm.sfc.event.CursorListener;
import com.gm.sfc.event.QueryEvent;
import com.gm.sfc.field.IField;
import com.gm.sfc.util.Utility;

/**
 * ロジックの親クラス
 * @author $Author: segen.der.gottin@gmail.com $
 * @version $Revision: 16 $
 */
public class ALogic implements ILogic {
    protected DatabaseHelper mDatabaseHelper;

    public LinkedList<HashMap<IField, Object>> execSelectSql(String sql) {
        try {
            final LinkedList<HashMap<IField, Object>> result = new LinkedList<HashMap<IField, Object>>();
            mDatabaseHelper.open();
            mDatabaseHelper.execSelect(sql, new CursorListener() {
                @Override
                public void onFinishQueryEvent(QueryEvent evt) {

                }

                @Override
                public void onEachQueryEvent(QueryEvent evt) {
                    result.add(Utility.convertToHashmap(evt.getCursor()));
                }
            });
            return result;
        } catch (Exception ex) {
            return null;
        }
    }
}
